// GTY


#include "ceshi/AuraSprint.h"

#include "Character/AuraCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"


UAuraSprint::UAuraSprint()
{
	NewMaxSpeed = 1000.f;
}

void UAuraSprint::ActivateAbility(
	const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
	const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData
)
{
	Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
}

void UAuraSprint::EndAbility(
	const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
	const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled
)
{
	if (ActorInfo && ActorInfo->AvatarActor.IsValid())
	{
		ACharacter* Character = Cast<ACharacter>(ActorInfo->AvatarActor.Get());
		if (Character)
		{
			UCharacterMovementComponent* MovementComponent = Character->GetCharacterMovement();
			if (MovementComponent)
			{
				// 恢复原始速度
				MovementComponent->MaxWalkSpeed = OriginalMaxSpeed;
				bIsSprinting = false;
			}
		}
	}

	Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);
}

void UAuraSprint::SetNewMaxSpeed()
{
	FGameplayAbilityActorInfo ActorInfo = GetActorInfo();
	ACharacter* Character = Cast<ACharacter>(ActorInfo.AvatarActor.Get());
	if (Character)
	{
		UCharacterMovementComponent* MovementComponent = Character->GetCharacterMovement();
		if (MovementComponent)
		{
			if (!bIsSprinting)
			{
				OriginalMaxSpeed = MovementComponent->MaxWalkSpeed;
				bIsSprinting = true;
			}
			
			
			// 设置新的最大速度
			MovementComponent->MaxWalkSpeed = NewMaxSpeed;
		}
	}
}


